import 'dart:convert';

import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/utils/log_util.dart';
import 'package:enterprise_v6_app/app/core/values/colors.dart';
import 'package:enterprise_v6_app/app/core/values/gaps.dart';
import 'package:enterprise_v6_app/app/data/entities/application/basic_information/co_regulatory_chemical_process_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/productive_process/hazardous_chemical_processes/hazardous_chemical_processes_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

///危险化工工艺页面
class HazardousChemicalProcessesPage extends StatelessWidget {
  HazardousChemicalProcessesPage({super.key});

  final controller = Get.put(HazardousChemicalProcessesController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            appBar: CustomAppBar(
              titleText: '危险化工工艺',
            ),
            body: Container(
              color: AppColors.bg_color_grey,
              padding: EdgeInsets.only(top: 12.w, right: 14.w, left: 14.w),
              child: CustomEasyRefreshList<CoRegulatoryChemicalProcessEntity>(
                isShowSearch: true,
                dataLoad: controller.getListData,
                searchHint: '请输入化工工艺名称',
                itemBuilder: (item, index) {
                  return CustomTitleChartPage(
                    title: item.keyDangerousChemicalsName!,
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        _rowData('涉及领域/工序：', item.areaOrProcess!),
                        AppGaps.vGap12,
                        // _rowData('负责人：', principalText(item.principal!)),
                        _rowData('负责人：', item.principal!),
                        AppGaps.vGap12,
                        _rowData('自控系统：', item.autoControlSysShow!),
                      ],
                    ),
                  );
                },
              ),
            ), // 右侧筛选栏
          );
        });
  }

  // 负责人显示
  String principalText(String principal) {
    String principalText = '';
    try {
      final List<dynamic> list = json.decode(principal) as List<dynamic>;
      principalText = list.join(', ');
    } catch (e) {
      AppLogger.printLog(e.toString());
    }
    return principalText;
  }

  Widget _rowData(String name, String value) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          width: 110.w,
          child: Text(
            name,
            style: TextStyle(
              color: const Color(0xFFA5A6B5),
              height: 1.2,
              fontWeight: FontWeight.w400,
              fontSize: 12.sp,
            ),
          ),
        ),
        AppGaps.hGap10,
        Expanded(
          child: Text(
            value,
            style: TextStyle(
              color: const Color(0xFF495061),
              height: 1.2,
              fontSize: 12.sp,
              fontWeight: FontWeight.w400,
            ),
          ),
        )
      ],
    );
  }
}
